<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>商品列表</span>
    </div>
    <div class="content">
      <el-table :data="data" style="width: 80%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="商品ID">
                <span>{{ props.row.id }}</span>
              </el-form-item>
              <el-form-item label="商品名称">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="所属分类">
                <span>{{ props.row.category }}</span>
              </el-form-item>
              <el-form-item label="商品价格">
                <span>{{ props.row.price }}</span>
              </el-form-item>
              <el-form-item label="商品图片">
                <img
                  :src="API + props.row.imgUrl"
                  width="80"
                  height="80"
                  alt=""
                />
              </el-form-item>
              <el-form-item label="创建时间">
                <span>{{ props.row.ctime }}</span>
              </el-form-item>
              <el-form-item label="商品评价">
                <span>{{ props.row.rating }}</span>
              </el-form-item>
              <el-form-item label="商品销量">
                <span>{{ props.row.sellCount }}</span>
              </el-form-item>
              <el-form-item label="商品描述">
                <span>{{ props.row.goodsDesc }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="商品名称" width="180">
        </el-table-column>
        <el-table-column prop="category" label="所属分类" width="180">
        </el-table-column>
        <el-table-column prop="price" label="商品价格"> </el-table-column>
        <el-table-column label="商品图片">
          <template slot-scope="scope">
            <div>
              <img
                :src="API + scope.row.imgUrl"
                width="80"
                height="80"
                alt=""
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="goodsDesc" label="商品描述"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-popconfirm
              confirm-button-text="确定"
              cancel-button-text="取消"
              icon="el-icon-info"
              icon-color="red"
              title="确定删除此账号吗？"
              @confirm="handleDelete(scope.row)"
              @cancel="canceldel"
            >
              <el-button
                slot="reference"
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >删除</el-button
              ></el-popconfirm
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 8, 5, 3]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      >
      </el-pagination>
    <el-dialog :visible.sync="dialogVisible" width="400"  > 
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>编辑商品信息</span>
          </div>
          <el-table ref="editInfo" :data="data" label-width="100px">
            <el-table-column label="商品名称" >
            <template  slot-scope="scope">
              <el-input v-model="scope.row.name" placeholder="scope.row.name"></el-input>
            </template>
            </el-table-column>
            <el-table-column  label="所属分类" prop="category">
              <el-input v-model="data.category"  autocomplete="off"></el-input>
            </el-table-column>
            <el-table-column label="商品价格" prop="price">
              <!-- <el-input v-model="price" autocomplete="off"></el-input> -->
            </el-table-column>
            <el-table-column  label="商品图片" prop="imgUrl">
              <!-- <el-input v-model="imgUrl" autocomplete="off"></el-input> -->
            </el-table-column>
            <el-table-column  label="商品描述" prop="goodsDesc">
              <!-- <el-input v-model="goodsDesc" autocomplete="off"></el-input> -->
            </el-table-column>
          </el-table>
        </el-card>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveeditinfo">确 定</el-button>

        </span>
      </el-dialog> 
    </div>
  </el-card>
</template>

<script>
import { getGoodslist, delGood, goodsmodify } from "@/api/goods";
export default {
  name: "GoodsList",
  data() {
    return {
      date:[{id:1,value:'3322',date:'2022-01-23'}],
      dialogVisible: false,
      data: [],
      API: "http://127.0.0.1:5000",
      currentPage: 1,
      pageSize: 6,
    };
  },
  methods: {
    async getData() {
      let res = await getGoodslist({
        currentPage: this.currentPage,
        pageSize: this.pageSize,
      });
      console.log(res);
      this.data = res.data.data;
    },
    handleEdit(a) {
      console.log(a,'222');
      this.dialogVisible = true;
    },
    handleDelete(b) {
      console.log(b);
    },
    canceldel() {
      this.$message({
        message: "取消成功",
        type: "success",
      });
    },
    saveeditinfo() {
      console.log(this.data);
      
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.el-form-item {
  width: 48%;
}
.el-button--danger {
  margin-left: 10px;
}
</style>
